﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using Database.Classes;
using System.Collections.Generic;


public partial class StoredProcedures
{
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void CreateGame()
    {
        string t = GetConfigurationForOption("MaxNumberOfSystems");
        int MaxNumberOfSystems = int.Parse(t);
        using (SqlConnection conn = new SqlConnection(StaticMethods.ConnectionString()))
        {
            conn.Open();
            WorldCreator wc = new WorldCreator();
            NameGenerator ng = new NameGenerator();
            for (int i = 1; i <= MaxNumberOfSystems; i++)
            {
                List<int> tmp = wc.NextSystem();
                if (CheckIfSystemExists(tmp[0], tmp[1]) == false)
                    CreateSystem(tmp[0], tmp[1], ng.NextName());
                else
                {//try again
                    i = i - 1;
                }
            }
        }
        int minPlanets =int.Parse( GetConfigurationForOption("MinNumberOfPlanetsPerSystem"));
        int maxPlanets = int.Parse(GetConfigurationForOption("MaxNumberOfPlanetsPerSystem"));
        Random r = new Random();
        for (int i = 1; i <= MaxNumberOfSystems; i++)
        {
            CreatePlanets(i, r.Next(minPlanets, maxPlanets));
        }

    }
};
